﻿//6. Write a method that returns the index of the first element in array that is bigger than its neighbors, or -1, if there’s no such element.


using System;
using System.Collections.Generic;

class FirstBiggerThenItsNeighborsElement
{
    static void Main()
    {
        int[] arr = { 1, 4, 4, 2, 7, 7, 5, 9, 8, 3, 4, 7, 9, 4 };
        Console.WriteLine(CompareWhitNeighbors(arr));
    }
    static int CompareWhitNeighbors(int[] arr)
    {
        for (int index = 0; index < arr.Length; index++)
        {
            if (index == 0 || index == arr.Length - 1)
            {
                if (index == 0 && arr[index] > arr[index + 1])
                {
                    return index;
                }
                else if (index == arr.Length - 1 && arr[index] > arr[index - 1])
                {
                    return index;
                }
            }
            else if (arr[index] > arr[index - 1] && arr[index] > arr[index + 1])
            {
                return index;
            }
        }
        return -1;
    }
}
